home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / workbench / directoryopus4 / dopus4_src / program / custom.c < prev    next >
C/C++ Source or Header  |  2000-03-11  |  55KB  |  1,523 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopus.h"
  32.  
  33. void defaultpar(par)
  34. struct dopusfuncpar *par;
  35. {
  36.     if (status_flags&STATUS_IANSCRAP) {
  37.         par->which=FLAG_OUTWIND;
  38.         par->delay=-1;
  39.     }
  40.     else {
  41.         par->which=FLAG_OUTWIND|FLAG_WB2F|FLAG_DOPUSF|FLAG_CDSOURCE;
  42.         par->delay=2;
  43.     }
  44.     par->key=par->qual=par->type=0;
  45.     par->pri=config->priority; par->stack=8000;
  46. }
  47.  
  48. void dofunctionstring(func,name,title,pars)
  49. char *func,*name,*title;
  50. struct dopusfuncpar *pars;
  51. {
  52.     char fbuf[256],*ptr;
  53.     int a,b,c,lb,ls,run=1,noloop=0,norm=1;
  54.     struct Directory *curcf;
  55.     struct function_data *funcdata;
  56.  
  57.     if (!func || !func[0] ||
  58.         !(funcdata=LAllocRemember(&general_key,sizeof(struct function_data),MEMF_CLEAR))) return;
  59.  
  60.     a=strlen(func);
  61.     status_flags&=~STATUS_VERIFYFAIL;
  62.     if (Window && !(status_flags&STATUS_FROMHOTKEY)) busy();
  63.  
  64.     funcdata->activewin=data_active_window;
  65.     funcdata->inactivewin=1-data_active_window;
  66.  
  67.     funcdata->file_request.window=Window;
  68.     funcdata->file_request.lines=15;
  69.  
  70.     if (func_external_file[0]) {
  71.         noloop=1;
  72.         if (ptr=BaseName(func_external_file))
  73.             strcpy(func_single_file,ptr);
  74.         strcpy(funcdata->source_path,func_external_file);
  75.         if (ptr=BaseName(funcdata->source_path)) *ptr=0;
  76.         norm=0;
  77.         if (!status_iconified)
  78.             strcpy(funcdata->dest_path,str_pathbuffer[data_active_window]);
  79.         funcdata->activewin=1-data_active_window;
  80.         funcdata->inactivewin=data_active_window;
  81.     }
  82.     else if (func_single_file[0]) noloop=1;
  83.     else if (status_iconified) norm=0;
  84.     else funcdata->entry_first=checkalltot(dopus_curwin[funcdata->activewin]);
  85.  
  86.     if (norm) {
  87.         strcpy(funcdata->source_path,str_pathbuffer[funcdata->activewin]);
  88.         strcpy(funcdata->dest_path,str_pathbuffer[funcdata->inactivewin]);
  89.     }
  90.  
  91.     status_justabort=status_haveaborted=0;
  92.  
  93.     FOREVER {
  94.         c=lb=0; ls=-1;
  95.  
  96.         curcf=funcdata->entry_first;
  97.  
  98.         for (b=0;b<a;b++) {
  99.             if (c>0 && func[b]=='|' && lb) {
  100.                 fbuf[c-1]=0; if (ls>-1) fbuf[ls]=0;
  101.                 c=lb=0;
  102.                 if (handlefunctionss(fbuf,name,title,pars,funcdata) ||
  103.                     status_flags&STATUS_VERIFYFAIL) {
  104.                     run=0;
  105.                     break;
  106.                 }
  107.             }
  108.             else {
  109.                 if (c>0 || !isspace(func[b])) {
  110.                     if (func[b]=='|' && func[b+1]=='|') lb=1;
  111.                     else if (isspace(func[b])) {
  112.                         if (ls==-1) ls=c;
  113.                     }
  114.                     else ls=-1;
  115.                     fbuf[c++]=func[b];
  116.                 }
  117.             }
  118.         }
  119.         if (c>0) {
  120.             fbuf[c]=0; if (ls>-1) fbuf[ls]=0;
  121.             if (handlefunctionss(fbuf,name,title,pars,funcdata) ||
  122.                 status_flags&STATUS_VERIFYFAIL) run=0;
  123.         }
  124.         if (!pars || !(pars->which&FLAG_DOALL) || status_justabort || status_haveaborted ||
  125.             status_flags&STATUS_VERIFYFAIL || !run || func_single_file[0] || noloop ||
  126.             !funcdata->external_flag) break;
  127.  
  128.         if (curcf && curcf==funcdata->entry_first)
  129.             funcdata->entry_first=funcdata->entry_first->next;
  130.  
  131.         while (funcdata->entry_first) {
  132.             if (funcdata->entry_first->selected) break;
  133.             funcdata->entry_first=funcdata->entry_first->next;
  134.         }
  135.  
  136.         if (!funcdata->entry_first) break;
  137.         funcdata->arg_use=funcdata->arg_first;
  138.         ++funcdata->function_count;
  139.     }
  140.     closescriptfile(pars,run,funcdata);
  141.     func_single_file[0]=0;
  142.     func_external_file[0]=0;
  143.     LFreeRemEntry(&general_key,(char *)funcdata);
  144.  
  145.     if (norm && Window) {
  146.         for (a=0;a<2;a++) check_old_buffer(a);
  147.     }
  148. }
  149.  
  150. handlefunctionss(funcbuf,name,title,pars,funcdata)
  151. char *funcbuf,*name,*title;
  152. struct dopusfuncpar *pars;
  153. struct function_data *funcdata;
  154. {
  155.     int function,abort=0,a,b;
  156.     char *funcptr,buf2[500],newfunc[500];
  157.     struct dopusfuncpar par;
  158.     struct Directory *didselect=NULL;
  159.  
  160.     func_single_entry=NULL;
  161.  
  162.     if (funcbuf[0]==FC_INTERNAL) {
  163.         b=strlen(funcbuf);
  164.         for (a=0;a<b;a++) if (funcbuf[a]=='{') break;
  165.         if (a<b) {
  166.             parserunline(funcbuf,buf2);
  167.             if (!(buildcustfunc(buf2,strlen(funcbuf),newfunc,NULL,0,0,0,funcdata)))
  168.                 return(1);
  169.             funcbuf=newfunc;
  170.         }
  171.         if ((function=getfunction(funcbuf,&funcptr))!=-1) {
  172.             if (function!=FUNC_HELP && status_flags&STATUS_HELP) {
  173.                 dohelp(name,funcbuf,pars?pars->key:0,pars?pars->qual:0,NULL);
  174.                 abort=1;
  175.             }
  176.             else if (function==FUNC_ENDFUNCTION) closescriptfile(pars,1,funcdata);
  177.             else {
  178.                 func_entry_deleted=0;
  179.                 if (func_single_file[0]) {
  180.                     if (func_external_file[0]) {
  181.                         if (filloutdummy(func_external_file,&funcdata->entry_external)) {
  182.                             funcdata->entry_external.selected=0;
  183.                             func_single_entry=&funcdata->entry_external;
  184.                         }
  185.                     }
  186.                     else if ((func_single_entry=
  187.                         findfile(dopus_curwin[funcdata->activewin],func_single_file,NULL))) {
  188.                         func_single_entry->selected=1;
  189.                         updateselectinfo(func_single_entry,funcdata->activewin,0);
  190.                         didselect=func_single_entry;
  191.                     }
  192.                 }
  193.  
  194.                 global_swap_window=FALSE;
  195.  
  196.                 if (funcptr) {
  197.                     func_global_function=function;
  198.                     rexxdisp(NULL,NULL,funcptr);
  199.                     if (func_global_function)
  200.                         abort=internal_function(func_global_function,rexx_global_flag,
  201.                             funcdata->source_path,funcdata->dest_path);
  202.                     func_global_function=0;
  203.                 }
  204.                 else abort=internal_function(function,0,funcdata->source_path,funcdata->dest_path);
  205.  
  206.                 if (global_swap_window) {
  207.                     funcdata->activewin=data_active_window;
  208.                     funcdata->inactivewin=1-data_active_window;
  209.  
  210.                     strcpy(funcdata->source_path,str_pathbuffer[funcdata->activewin]);
  211.                     strcpy(funcdata->dest_path,str_pathbuffer[funcdata->inactivewin]);
  212.  
  213.                     funcdata->entry_first=checkalltot(dopus_curwin[funcdata->activewin]);
  214.                 }
  215.  
  216.                 if (didselect && !func_entry_deleted && didselect->selected) {
  217.                     didselect->selected=0;
  218.                     updateselectinfo(didselect,funcdata->activewin,0);
  219.                 }
  220.                 func_single_entry=NULL; func_entry_deleted=0;
  221.             }
  222.         }
  223.     }
  224.     else {
  225.         funcdata->external_flag=1;
  226.         if (status_flags&STATUS_HELP) {
  227.             dohelp(name,funcbuf,pars?pars->key:0,pars?pars->qual:0,NULL);
  228.             abort=1;
  229.         }
  230.         else {
  231.             if (pars) CopyMem((char *)pars,(char *)&par,sizeof(struct dopusfuncpar));
  232.             else defaultpar(&par);
  233.             switch (funcbuf[0]) {
  234.                 case FC_WORKBENCH: par.type=FT_WORKBENCH; ++funcbuf; break;
  235.                 case FC_BATCH: par.type=FT_BATCH; ++funcbuf; break;
  236.                 case FC_AREXX: par.type=FT_AREXX; ++funcbuf; break;
  237.                 case FC_CHDIR: par.type=FT_CHDIR; ++funcbuf; break;
  238.                 default: par.type=FT_EXECUTABLE; break;
  239.             }
  240.             if (!(customthing(name,title,funcbuf,&par,funcdata))) abort=1;
  241.         }
  242.     }
  243.     return(abort);
  244. }
  245.  
  246. getfunction(func,funcptr)
  247. char *func,**funcptr;
  248. {
  249.     int a,b;
  250.  
  251.     if (funcptr) *funcptr=NULL;
  252.     if (!func) return(-1);
  253.     if (func[0]==FC_INTERNAL) {
  254.         b=0;
  255.         FOREVER {
  256.             if (commandlist[b].name==NULL) break;
  257.             a=strlen(commandlist[b].name);
  258.             if (LStrnCmpI(commandlist[b].name,&func[1],a)==0 &&
  259.                 (isspace(func[a+1]) || func[a+1]==0)) {
  260.                 if (funcptr && func[a+1]) *funcptr=&func[a+1];
  261.                 return((int)commandlist[b].function);
  262.             }
  263.             ++b;
  264.         }
  265.     }
  266.     return(-1);
  267. }
  268.  
  269. customthing(name,title,function,par,funcdata)
  270. char *name,*title,*function;
  271. struct dopusfuncpar *par;
  272. struct function_data *funcdata;
  273. {
  274.     int moretodo,a,b,len,tot,type,count;
  275.     unsigned char buf[500],*ptr;
  276.     char buf2[500],tbuf[512];
  277.     struct args *usearg,*endarg;
  278.  
  279.     if ((!name || !name[0]) && (!function || !function[0])) return(1);
  280.     if (Window && !status_iconified && !(status_flags&STATUS_FROMHOTKEY)) {
  281.         if (title) dostatustext(title);
  282.         else if (name) dostatustext(name);
  283.     }
  284.  
  285.     if ((type=par->type)==FT_AREXX) {
  286.         rexx_command(function,NULL);
  287.         return(1);
  288.     }
  289.  
  290.     if (!(openscriptfile(par,funcdata))) return(0);
  291.     if (type==FT_CHDIR) {
  292.         b=strlen(function);
  293.         for (a=1;a<b;a++) if (function[a]=='!') break;
  294.         LStrnCpy(buf2,&function[1],a-1);
  295.         lsprintf(tbuf,"CD %s\n",buf2);
  296.         Write(funcdata->output_file,tbuf,strlen(tbuf));
  297.         return(1);
  298.     }
  299.  
  300.     tot=1;
  301.  
  302.     if (!function[0]) {
  303.         ptr=(unsigned char *)name;
  304.         while (*ptr) {
  305.             if (*ptr==';') *ptr='\n';
  306.             ++ptr;
  307.         }
  308.         lsprintf(tbuf,"%s\n",name);
  309.         Write(funcdata->output_file,tbuf,strlen(tbuf));
  310.     }
  311.     else {
  312.         parserunline(function,buf);
  313.         ptr=buf;
  314.         while (*ptr) {
  315.             if (*ptr==';') *ptr='\n';
  316.             ++ptr;
  317.         }
  318.         len=strlen((char *)buf);
  319.  
  320.         count=funcdata->function_count;
  321.         endarg=usearg=funcdata->arg_use;
  322.  
  323.         FOREVER {
  324.             if (status_haveaborted) {
  325.                 closescriptfile(NULL,0,funcdata);
  326.                 myabort();
  327.                 tot=0;
  328.                 break;
  329.             }
  330.             moretodo=0;
  331.             if (!(buildcustfunc(buf,len,buf2,&moretodo,par->which&FLAG_RECURSE,par->which&FLAG_RELOAD,
  332.                 ((par->which&FLAG_NOQUOTE)?0:1),funcdata))) {
  333.                 closescriptfile(NULL,0,funcdata);
  334.                 tot=0;
  335.                 break;
  336.             }
  337.             if (type==FT_BATCH) Write(funcdata->output_file,"Execute ",8);
  338.             else if (type==FT_WORKBENCH) {
  339.                 lsprintf(tbuf,"%s -r ",str_dopusrt_path);
  340.                 Write(funcdata->output_file,tbuf,strlen(tbuf));
  341.             }
  342.             lsprintf(tbuf,"%s\n",buf2);
  343.             Write(funcdata->output_file,tbuf,strlen(tbuf));
  344.             if (moretodo &&
  345.                 (funcdata->entry_first || funcdata->file_request.filearray)) goto domorestuff;
  346.             if (!funcdata->recursive_path) break;
  347. domorestuff:
  348.             funcdata->function_count=-1;
  349.             endarg=funcdata->arg_use;
  350.             if (usearg) funcdata->arg_use=usearg->next;
  351.             if (!funcdata->arg_use) {
  352.                 if (usearg) funcdata->arg_use=usearg;
  353.                 else funcdata->arg_use=funcdata->arg_first;
  354.             }
  355.         }
  356.         funcdata->function_count=count;
  357.         funcdata->arg_use=endarg;
  358.         if (funcdata->activewin>-1)
  359.             funcdata->entry_first=checkalltot(dopus_curwin[funcdata->activewin]);
  360.     }
  361.     if (funcdata->file_request.filearray) {
  362.         LFreeRemember(&funcdata->file_request.filearraykey);
  363.         funcdata->file_request.filearray=NULL;
  364.     }
  365.     return(tot);
  366. }
  367.  
  368. buildcustfunc(function,line_len,buffer,moretodo,star,reload,quote,funcdata)
  369. unsigned char *function;
  370. int line_len;
  371. char *buffer;
  372. int *moretodo,star,reload,quote;
  373. struct function_data *funcdata;
  374. {
  375.     char buf3[500],*ptr,filebuf[32],dirbuf[256],*spath,defbuf[256],titlebuf[80];
  376.     int a,pos,bufpos,d,f,sblen,buftitpos,h,qad,def,tit;
  377.     struct Directory *cust,dummy;
  378.     struct args *arg;
  379.  
  380.     buffer[0]=buf3[0]=dirbuf[0]=0;
  381.     qad=quote*2;
  382.  
  383.     for (bufpos=0;bufpos<500;bufpos++) buffer[bufpos]=buf3[bufpos]=0;
  384.     bufpos=0;
  385.  
  386.     sblen=strlen(funcdata->source_path);
  387.  
  388.     for (pos=0;pos<line_len;pos++) {
  389.         switch (function[pos]) {
  390.             case FUNC_ONEFILE:
  391.             case FUNC_ONEFILE_NO:
  392.                 if (!func_single_file[0]) {
  393.                     if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
  394.                         if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
  395.                         else return(0);
  396.                     }
  397.                     else if (!funcdata->recursive_path) cust=custgetfirst(funcdata);
  398.                     if (cust) {
  399.                         strcpy(funcdata->last_file,funcdata->source_path);
  400.                         TackOn(funcdata->last_file,cust->name,256);
  401.                         if (!funcdata->recursive_path && cust->type>0) {
  402.                             if (star) {
  403.                                 LFreeRemember(&rec_pathkey);
  404.                                 funcdata->entry_current=cust;
  405.                                 StrCombine(buf3,funcdata->source_path,cust->name,256);
  406.                                 if (recursedir(buf3,NULL,R_STARDIR,strlen(funcdata->source_path)))
  407.                                     return(0);
  408.                                 setdirsize(cust,dos_global_bytecount,funcdata->activewin);
  409.                                 funcdata->recursive_path=rec_firstpath;
  410.                                 goto addfile1;
  411.                             }
  412.                             else {
  413.                                 bufpos+=addfilename(buffer,cust->name,NULL,quote);
  414.                                 if (function[pos]!=FUNC_ONEFILE_NO) {
  415.                                     custunselect(cust,reload,funcdata);
  416.                                     custnextsel(&funcdata->entry_first);
  417.                                 }
  418.                             }
  419.                         }
  420.                         else {
  421. addfile1:
  422.                             if (funcdata->recursive_path) {
  423.                                 bufpos+=addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
  424.                                 if (!(funcdata->recursive_path=funcdata->recursive_path->next) &&
  425.                                     function[pos]!=FUNC_ONEFILE_NO)
  426.                                     custunselect(funcdata->entry_current,reload,funcdata);
  427.                             }
  428.                             else {
  429.                                 bufpos+=addfilename(buffer,cust->name,NULL,quote);
  430.                                 if (function[pos]!=FUNC_ONEFILE_NO) {
  431.                                     custunselect(cust,reload,funcdata);
  432.                                     custnextsel(&funcdata->entry_first);
  433.                                 }
  434.                             }
  435.                         }
  436.                     }
  437.                 }
  438.                 else {
  439.                     strcpy(funcdata->last_file,func_single_file);
  440.                     bufpos+=addfilename(buffer,func_single_file,NULL,quote);
  441.                 }
  442.                 break;
  443.  
  444.             case FUNC_ALLFILES:
  445.             case FUNC_ALLFILES_NO:
  446.                 if (!func_single_file[0]) {
  447.                     a=d=strlen(buffer);
  448.                     if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
  449.                         if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
  450.                         else return(0);
  451.                     }
  452.                     else cust=custgetfirst(funcdata);
  453.                     while (a<256 && (cust || funcdata->recursive_path)) {
  454.                         if (funcdata->recursive_path || (cust->selected && cust->type!=0)) {
  455.                             if (!funcdata->recursive_path && cust->type>0) {
  456.                                 if (star) {
  457.                                     LFreeRemember(&rec_pathkey);
  458.                                     funcdata->entry_current=cust;
  459.                                     StrCombine(buf3,funcdata->source_path,cust->name,256);
  460.                                     if (recursedir(buf3,NULL,R_STARDIR,strlen(funcdata->source_path)))
  461.                                         return(0);
  462.                                     setdirsize(cust,dos_global_bytecount,funcdata->activewin);
  463.                                     funcdata->recursive_path=rec_firstpath;
  464.                                     goto addfile2;
  465.                                 }
  466.                                 else {
  467.                                     if ((a+strlen(cust->name)+qad)>255) break;
  468.                                     addfilename(buffer,cust->name,NULL,quote);
  469.                                     if (function[pos]!=FUNC_ALLFILES_NO)
  470.                                         custunselect(cust,reload,funcdata);
  471.                                 }
  472.                             }
  473.                             else {
  474. addfile2:
  475.                                 if (funcdata->recursive_path) {
  476.                                     if ((a+strlen(funcdata->recursive_path->path)+qad)>255) break;
  477.                                     addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
  478.                                     if (!(funcdata->recursive_path=funcdata->recursive_path->next)) {
  479.                                         if (function[pos]!=FUNC_ALLFILES_NO)
  480.                                             custunselect(funcdata->entry_current,reload,funcdata);
  481.                                     }
  482.                                 }
  483.                                 else {
  484.                                     if ((a+strlen(cust->name)+qad)>255) break;
  485.                                     addfilename(buffer,cust->name,NULL,quote);
  486.                                     if (function[pos]!=FUNC_ALLFILES_NO)
  487.                                         custunselect(cust,reload,funcdata);
  488.                                 }
  489.                             }
  490.                             StrConcat(buffer," ",256);
  491.                             a=strlen(buffer);
  492.                         }
  493.                         if (!funcdata->recursive_path) {
  494.                             if (cust) cust=cust->next;
  495.                             custnextsel(&funcdata->entry_first);
  496.                         }
  497.                     }
  498.                     bufpos+=a-d;
  499.                     if (moretodo) *moretodo=1;
  500.                 }
  501.                 else {
  502.                     bufpos+=addfilename(buffer,func_single_file,NULL,quote);
  503.                     StrConcat(buffer," ",256);
  504.                     ++bufpos;
  505.                 }
  506.                 break;
  507.  
  508.             case FUNC_ONEPATH:
  509.             case FUNC_ONEPATH_NO:
  510.                 if (!func_single_file[0]) {
  511.                     if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
  512.                         if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
  513.                         else return(0);
  514.                         TackOn(dirbuf,NULL,256);
  515.                         spath=dirbuf;
  516.                     }
  517.                     else {
  518.                         if (!funcdata->recursive_path) cust=custgetfirst(funcdata);
  519.                         spath=funcdata->source_path;
  520.                     }
  521.                     if (cust) {
  522.                         strcpy(funcdata->last_file,spath);
  523.                         TackOn(funcdata->last_file,cust->name,256);
  524.                         if (!funcdata->recursive_path && cust->type>0) {
  525.                             if (star) {
  526.                                 LFreeRemember(&rec_pathkey);
  527.                                 funcdata->entry_current=cust;
  528.                                 StrCombine(buf3,spath,cust->name,256);
  529.                                 if (recursedir(buf3,NULL,R_STARDIR,0)) return(0);
  530.                                 setdirsize(cust,dos_global_bytecount,funcdata->activewin);
  531.                                 funcdata->recursive_path=rec_firstpath;
  532.                                 goto addfile3;
  533.                             }
  534.                             else {
  535.                                 bufpos+=addfilename(buffer,spath,cust->name,quote);
  536.                                 if (function[pos]!=FUNC_ONEPATH_NO) {
  537.                                     custunselect(cust,reload,funcdata);
  538.                                     custnextsel(&funcdata->entry_first);
  539.                                 }
  540.                             }                   
  541.                         }
  542.                         else {
  543. addfile3:
  544.                             if (funcdata->recursive_path) {
  545.                                 bufpos+=addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
  546.                                 if (!(funcdata->recursive_path=funcdata->recursive_path->next) && function[pos]!=FUNC_ONEPATH_NO)
  547.                                     custunselect(funcdata->entry_current,reload,funcdata);
  548.                             }
  549.                             else {
  550.                                 bufpos+=addfilename(buffer,spath,cust->name,quote);
  551.                                 if (function[pos]!=FUNC_ONEPATH_NO) {
  552.                                     custunselect(cust,reload,funcdata);
  553.                                     custnextsel(&funcdata->entry_first);
  554.                                 }
  555.                             }
  556.                         }
  557.                     }
  558.                 }
  559.                 else {
  560.                     bufpos+=addfilename(buffer,funcdata->source_path,func_single_file,quote);
  561.                     strcpy(funcdata->last_file,funcdata->source_path);
  562.                     TackOn(funcdata->last_file,func_single_file,256);
  563.                 }
  564.                 break;
  565.  
  566.             case FUNC_ALLPATHS:
  567.             case FUNC_ALLPATHS_NO:
  568.                 if (!func_single_file[0]) {
  569.                     a=d=strlen(buffer);
  570.                     if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
  571.                         if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
  572.                         else return(0);
  573.                         TackOn(dirbuf,NULL,256);
  574.                         spath=dirbuf;
  575.                     }
  576.                     else {
  577.                         cust=custgetfirst(funcdata);
  578.                         spath=funcdata->source_path;
  579.                     }
  580.                     while (a<256 && (cust || funcdata->recursive_path)) {
  581.                         if (funcdata->recursive_path || (cust->selected && cust->type!=0)) {
  582.                             if (!funcdata->recursive_path && cust->type>0) {
  583.                                 if (star) {
  584.                                     LFreeRemember(&rec_pathkey);
  585.                                     funcdata->entry_current=cust;
  586.                                     StrCombine(buf3,spath,cust->name,256);
  587.                                     if (recursedir(buf3,NULL,R_STARDIR,0)) return(0);
  588.                                     setdirsize(cust,dos_global_bytecount,funcdata->activewin);
  589.                                     funcdata->recursive_path=rec_firstpath;
  590.                                     goto addfile4;
  591.                                 }
  592.                                 else {
  593.                                     if ((a+strlen(cust->name)+strlen(spath)+qad)>255) break;
  594.                                     addfilename(buffer,spath,cust->name,quote);
  595.                                     if (function[pos]!=FUNC_ALLPATHS_NO)
  596.                                         custunselect(cust,reload,funcdata);
  597.                                 }   
  598.                             }
  599.                             else {
  600. addfile4:
  601.                                 if (funcdata->recursive_path) {
  602.                                     if ((a+strlen(funcdata->recursive_path->path)+qad)>255) break;
  603.                                     addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
  604.                                     if (!(funcdata->recursive_path=funcdata->recursive_path->next)) {
  605.                                         if (function[pos]!=FUNC_ALLPATHS_NO)
  606.                                             custunselect(funcdata->entry_current,reload,funcdata);
  607.                                     }
  608.                                 }
  609.                                 else {
  610.                                     if ((a+strlen(cust->name)+strlen(spath)+qad)>255) break;
  611.                                     addfilename(buffer,spath,cust->name,quote);
  612.                                     if (function[pos]!=FUNC_ALLPATHS_NO)
  613.                                         custunselect(cust,reload,funcdata);
  614.                                 }
  615.                             }
  616.                             StrConcat(buffer," ",256);
  617.                             a=strlen(buffer);
  618.                         }
  619.                         if (!funcdata->recursive_path) {
  620.                             if (cust) cust=cust->next;
  621.                             custnextsel(&funcdata->entry_first);
  622.                         }
  623.                     }
  624.                     bufpos+=a-d;
  625.                     if (moretodo) *moretodo=1;
  626.                 }
  627.                 else {
  628.                     bufpos+=addfilename(buffer,funcdata->source_path,func_single_file,quote);
  629.                     StrConcat(buffer," ",256);
  630.                     ++bufpos;
  631.                 }
  632.                 break;
  633.  
  634.             case FUNC_SOURCE:
  635.             case FUNC_SOURCE_RR:
  636.                 strcpy(buf3,funcdata->source_path);
  637.                 if ((status_iconified || status_flags&STATUS_FROMHOTKEY)) {
  638.                     if (dirrequester(&funcdata->file_request,buf3,
  639.                         globstring[STR_SELECT_SOURCE_DIR])) {
  640.                         myabort();
  641.                         return(0);
  642.                     }
  643.                     StrConcat(buffer,buf3,256);
  644.                     bufpos=strlen(buffer);
  645.                 }
  646.                 else {
  647.                     StrConcat(buffer,funcdata->source_path,256);
  648.                     bufpos+=sblen;
  649.                 }
  650.             case FUNC_NOSOURCE_RR:
  651.                 if (function[pos]!=FUNC_SOURCE) funcdata->rereadsource=1;
  652.                 break;
  653.  
  654.             case FUNC_DEST:
  655.             case FUNC_DEST_RR:
  656.                 if (!(check_dest_path(funcdata))) return(0);
  657.                 StrConcat(buffer,funcdata->dest_path,256);
  658.                 bufpos+=strlen(funcdata->dest_path);
  659.             case FUNC_NODEST_RR:
  660.                 if (function[pos]!=FUNC_DEST) funcdata->rereaddest=1;
  661.                 break;
  662.  
  663.             case FUNC_SCREENNAME:
  664.                 StrConcat(buffer,str_arexx_portname,256);
  665.                 bufpos+=strlen(str_arexx_portname);
  666.                 break;
  667.  
  668.             case FUNC_QUERYINFO:
  669.                 ++pos;
  670.                 {
  671.                     char *data=NULL;
  672.  
  673.                     switch (function[pos]) {
  674.  
  675.                         /* Public screen name */
  676.                         case 's':
  677.                             data=get_our_pubscreen();
  678.                             break;
  679.  
  680.                         /* ARexx port name */
  681.                         case 'p':
  682.                             data=str_arexx_portname;
  683.                             break;
  684.  
  685.                         /* Last result */
  686.                         case 'r':
  687.                             data=str_last_rexx_result;
  688.                             break;
  689.                     }
  690.  
  691.                     if (data && data[0]) {
  692.                         StrConcat(buffer,data,256);
  693.                         bufpos+=strlen(data);
  694.                     }
  695.                 }
  696.                 break;
  697.  
  698.             case FUNC_VARIABLE:
  699.                 tit=0;
  700.  
  701.                 for (pos++;pos<line_len;pos++) {
  702.                     if (function[pos]==FUNC_ENDARG) break;
  703.                     if (tit<79) titlebuf[tit++]=function[pos];
  704.                 }
  705.                 titlebuf[tit]=0;
  706.  
  707.                 if (system_version2) {
  708.                     if ((a=GetVar(titlebuf,buf3,500,0))>0) {
  709.                         StrConcat(buffer,buf3,256);
  710.                         bufpos+=a;
  711.                     }
  712.                 }
  713.                 break;
  714.  
  715.             case FUNC_GETARG:
  716.                 if (funcdata->function_count && funcdata->arg_use) {
  717. use_old_arg:
  718.                     StrConcat(buffer,funcdata->arg_use->argstring,256);
  719.                     bufpos+=strlen(funcdata->arg_use->argstring);
  720.                     funcdata->arg_use=funcdata->arg_use->next;
  721.                     for (f=pos+1;f<line_len && function[f]!=FUNC_ENDARG;f++);
  722.                     pos=f;
  723.                     break;
  724.                 }
  725.             case FUNC_STDARG:
  726.                 if (funcdata->function_count==-1 && funcdata->arg_use) goto use_old_arg;
  727.                 buftitpos=-1;
  728.                 def=0;
  729.                 tit=0;
  730.  
  731.                 for (f=pos+1;f<line_len;f++) {
  732.                     if (function[f]==FUNC_ENDARG) break;
  733.                     else if (buftitpos==-1) {
  734.                         if (function[f]==':') buftitpos=f+1;
  735.                         else if (tit<79) titlebuf[tit++]=function[f];
  736.                     }
  737.                     else if (def<255) defbuf[def++]=function[f];
  738.                 }
  739.                 titlebuf[tit]=0;
  740.                 defbuf[def]=0;
  741.  
  742.                 if (!titlebuf[0]) ptr=globstring[STR_ENTER_ARGUMENTS];
  743.                 else ptr=titlebuf;
  744.  
  745.                 buf3[0]=0;
  746.                 if (buftitpos>-1)
  747.                     build_default_string(defbuf,buf3,funcdata->last_file,funcdata->source_path,funcdata->dest_path);
  748.  
  749.                 if (!(whatsit(ptr,256,buf3,NULL))) {
  750.                     myabort();
  751.                     return(0);
  752.                 }
  753.  
  754.                 if (function[pos]==FUNC_GETARG) {
  755.                     if (!(arg=LAllocRemember(&funcdata->arg_memkey,sizeof(struct args),MEMF_CLEAR)))
  756.                         return(0);
  757.                     if (!funcdata->arg_first) funcdata->arg_first=arg;
  758.                     else funcdata->arg_current->next=arg;
  759.                     funcdata->arg_current=arg;
  760.                     strcpy(funcdata->arg_current->argstring,buf3);
  761.                 }
  762.                 StrConcat(buffer,buf3,256);
  763.                 bufpos+=strlen(buf3);
  764.                 pos=f;
  765.                 break;
  766.  
  767.             case FUNC_REQUESTER:
  768.                 if (funcdata->file_request.filearray) {
  769. domultifiles:
  770.                     while (bufpos<256) {
  771.                         if (funcdata->file_request.filearray[funcdata->fileargpos][0]) {
  772.                             if ((bufpos+strlen(funcdata->file_request.filearray[funcdata->fileargpos])+qad)<256) {
  773.                                 bufpos+=addfilename(buffer,
  774.                                     funcdata->file_request.filearray[funcdata->fileargpos],NULL,quote);
  775.                                 StrConcat(buffer," ",256); ++bufpos;
  776.                                 ++funcdata->fileargpos;
  777.                             }
  778.                             else {
  779.                                 if (moretodo) *moretodo=1;
  780.                                 break;
  781.                             }
  782.                         }
  783.                         if (!funcdata->file_request.filearray[funcdata->fileargpos][0]) {
  784.                             LFreeRemember(&funcdata->file_request.filearraykey);
  785.                             funcdata->file_request.filearray=NULL;
  786.                             break;
  787.                         }
  788.                     }
  789.                     for (f=pos+1;f<line_len;f++)
  790.                         if (function[f]==FUNC_ENDARG || function[f]==0) break;
  791.                     pos=f;
  792.                     break;
  793.                 }
  794.                 h=-1;
  795.                 switch (function[pos+1]) {
  796.                     case 'f': h=0; break;
  797.                     case 'F': h=DFRF_MULTI; break;
  798.                     case 'd': h=DFRF_DIRREQ; break;
  799.                     case 'o': h=DFRF_FONT; break;
  800.                 }
  801.                 if (h==-1) break;
  802.                 ++pos;
  803.                 buftitpos=-1;
  804.                 for (f=pos+1;f<line_len;f++) {
  805.                     if (function[f]==':' && buftitpos==-1) {
  806.                         function[f]=0;
  807.                         buftitpos=f+1;
  808.                     }
  809.                     if (function[f]==FUNC_ENDARG) {
  810.                         function[f]=0;
  811.                         break;
  812.                     }
  813.                 }
  814.                 if (!function[(pos+1)]) funcdata->file_request.title=globstring[STR_FILE_REQUEST];
  815.                 else funcdata->file_request.title=(char *)function+pos+1;
  816.                 buf3[0]=0;
  817.                 if (buftitpos>-1)
  818.                     build_default_string(&function[buftitpos],buf3,funcdata->last_file,funcdata->source_path,funcdata->dest_path);
  819.                 else if (h&DFRF_FONT) strcpy(buf3,"FONTS:");
  820.                 funcdata->file_request.dirbuf=buf3;
  821.                 funcdata->file_request.filebuf=filebuf; filebuf[0]=0;
  822.                 if (!(h&DFRF_DIRREQ)) {
  823.                     ptr=BaseName(buf3);
  824.                     if (ptr>buf3) {
  825.                         if (ptr[(strlen(ptr)-1)]!='/') {
  826.                             strcpy(filebuf,ptr);
  827.                             *ptr=0;
  828.                         }
  829.                     }
  830.                 }
  831.                 funcdata->file_request.flags=h;
  832.                 if (FileRequest(&funcdata->file_request)) {
  833.                     if (h&DFRF_MULTI) {
  834.                         funcdata->fileargpos=0;
  835.                         goto domultifiles;
  836.                     }
  837.                     if (!funcdata->file_request.dirbuf[0])
  838.                         expand_path("",funcdata->file_request.dirbuf);
  839.                     if (!(h&DFRF_DIRREQ)) {
  840.                         if (quote) StrConcat(buffer,"\"",256);
  841.                         StrConcat(buffer,funcdata->file_request.dirbuf,256);
  842.                         TackOn(buffer,filebuf,256);
  843.                         if (quote) StrConcat(buffer,"\"",256);
  844.                     }
  845.                     else StrConcat(buffer,funcdata->file_request.dirbuf,256);
  846.                     bufpos=strlen(buffer);
  847.                 }
  848.                 else {
  849.                     myabort();
  850.                     return(0);
  851.                 }
  852.                 pos=f;
  853.                 break;
  854.             default:
  855.                 buffer[bufpos++]=function[pos];
  856.                 break;
  857.         }
  858.         if (bufpos==256) break;
  859.     }
  860.     buffer[255]=0;
  861.     return(1);
  862. }
  863.  
  864. addfilename(buf,part1,part2,quote)
  865. char *buf,*part1,*part2;
  866. int quote;
  867. {
  868.     int c=0,d;
  869.  
  870.     d=strlen(buf);
  871.     if (d>0 && !(isspace(buf[d-1]))) quote=0;
  872.  
  873.     if (quote) {
  874.         StrConcat(buf,"\"",256);
  875.         ++c;
  876.     }
  877.     if (part1) {
  878.         StrConcat(buf,part1,256);
  879.         c+=strlen(part1);
  880.     }
  881.     if (part2) {
  882.         StrConcat(buf,part2,256);
  883.         c+=strlen(part2);
  884.     }
  885.     if (quote) {
  886.         StrConcat(buf,"\"",256);
  887.         ++c;
  888.     }
  889.     return(c);
  890. }
  891.  
  892. void parserunline(buf,buf1)
  893. char *buf;
  894. unsigned char *buf1;
  895. {
  896.     int a,b,c,d;
  897.  
  898.     a=strlen(buf);
  899.     for (c=0;c<256;c++) buf1[c]=0;
  900.     c=0;
  901.     for (b=0;b<a;b++) {
  902.         if (c==256) break;
  903.         if (buf[b]=='{') {
  904.             if ((b+2)>=a) {
  905.                 buf1[c]=buf[b];
  906.                 ++c;
  907.                 continue;
  908.             }
  909.             if (buf[(b+1)]=='{') {
  910.                 buf1[c]=buf[b];
  911.                 ++b; ++c;
  912.                 continue;
  913.             }
  914.  
  915.             switch (buf[(b+1)]) {
  916.                 case 'a':
  917.                     buf1[c]=FUNC_GETARG;
  918.                 case 'A':
  919.                     if (buf[(b+1)]=='A') buf1[c]=FUNC_STDARG;
  920.                 case 'v':
  921.                     if (buf[(b+1)]=='v') buf1[c]=FUNC_VARIABLE;
  922.                 case 'R':
  923.                     if (buf[(b+1)]=='R') {
  924.                         if (buf[(b+2)]=='s') {
  925.                             buf1[c]=FUNC_GETARG;
  926.                             ++b;
  927.                         }
  928.                         else if (buf[(b+2)]=='S') {
  929.                             buf1[c]=FUNC_STDARG;
  930.                             ++b;
  931.                         }
  932.                         else buf1[c]=FUNC_REQUESTER;
  933.                     }
  934.                     ++c;
  935.                     for (d=(b+2);d<a;d++) {
  936.                         if (buf[d]=='}') break;
  937.                         buf1[c]=buf[d];
  938.                         ++c;
  939.                         if (c==255) break;
  940.                     }
  941.                     buf1[c++]=FUNC_ENDARG;
  942.                     b=d;
  943.                     continue;
  944.  
  945.                 case 'Q':
  946.                     buf1[c++]=FUNC_QUERYINFO;
  947.                     buf1[c++]=buf[b+2];
  948.                     b+=3;
  949.                     continue;
  950.             }
  951.  
  952.             switch (buf[(b+2)]) {
  953.                 case 'r':
  954.                     if (buf[(b+1)]=='d') buf1[c]=FUNC_DEST_RR;
  955.                     else if (buf[(b+1)]=='s') buf1[c]=FUNC_SOURCE_RR;
  956.                     else if (buf[(b+1)]=='S') buf1[c]=FUNC_NOSOURCE_RR;
  957.                     else if (buf[(b+1)]=='D') buf1[c]=FUNC_NODEST_RR;
  958.                     b+=3; ++c;
  959.                     continue;
  960.  
  961.                 case 'u':
  962.                     if (buf[(b+1)]=='o') buf1[c]=FUNC_ONEFILE_NO;
  963.                     else if (buf[(b+1)]=='O') buf1[c]=FUNC_ALLFILES_NO;
  964.                     else if (buf[(b+1)]=='f') buf1[c]=FUNC_ONEPATH_NO;
  965.                     else if (buf[(b+1)]=='F') buf1[c]=FUNC_ALLPATHS_NO;
  966.                     b+=3; ++c;
  967.                     continue;
  968.  
  969.                 case '}':
  970.                     switch (buf[(b+1)]) {
  971.                         case 'o': buf1[c]=FUNC_ONEFILE; break;
  972.                         case 'O': buf1[c]=FUNC_ALLFILES; break;
  973.                         case 's': buf1[c]=FUNC_SOURCE; break;
  974.                         case 'd': buf1[c]=FUNC_DEST; break;
  975.                         case 'f': buf1[c]=FUNC_ONEPATH; break;
  976.                         case 'F': buf1[c]=FUNC_ALLPATHS; break;
  977.                         case 'p': buf1[c]=FUNC_SCREENNAME; break;
  978.                     }
  979.                     b+=2; ++c;
  980.                     continue;
  981.             }
  982.         }
  983.         buf1[c]=buf[b];
  984.         ++c;
  985.         if (c==256) break;
  986.     }
  987. }
  988.  
  989. void custunselect(dir,rel,funcdata)
  990. struct Directory *dir;
  991. int rel;
  992. struct function_data *funcdata;
  993. {
  994.     struct recpath *temp;
  995.     int win;
  996.  
  997.     win=funcdata->activewin;
  998.  
  999.     if (!status_iconified && !(status_flags&STATUS_FROMHOTKEY) && !func_external_file[0]) {
  1000.         if (rel && dir->name[0]) {
  1001.             if ((temp=LAllocRemember(&funcdata->reload_memkey,sizeof(struct recpath),MEMF_CLEAR)) &&
  1002.                 (temp->path=LAllocRemember(&funcdata->reload_memkey,33,MEMF_CLEAR))) {
  1003.                 strcpy(temp->path,dir->name);
  1004.                 if (funcdata->reload_current) funcdata->reload_current->next=temp;
  1005.                 funcdata->reload_current=temp;
  1006.                 if (!funcdata->reload_first) funcdata->reload_first=temp;
  1007.                 temp->next=NULL;
  1008.             }
  1009.         }
  1010.         unselect(win,dir);
  1011.     }
  1012. }
  1013.  
  1014. void doreloadfiles(funcdata)
  1015. struct function_data *funcdata;
  1016. {
  1017.     char buf[256];
  1018.     struct recpath *rel;
  1019.     int off;
  1020.  
  1021.     rel=funcdata->reload_first;
  1022.     off=dopus_curwin[funcdata->activewin]->offset;
  1023.     while (rel) {
  1024.         StrCombine(buf,funcdata->source_path,rel->path,256);
  1025.         reload_file(funcdata->activewin,buf);
  1026.         rel=rel->next;
  1027.     }
  1028.     dopus_curwin[funcdata->activewin]->offset=off;
  1029.     refreshwindow(funcdata->activewin,0);
  1030. }
  1031.  
  1032. struct Directory *reload_file(win,name)
  1033. int win;
  1034. char *name;
  1035. {
  1036.     struct FileInfoBlock __aligned fileinfo;
  1037.     struct Directory *cust,*ret=NULL;
  1038.  
  1039.     if ((lockandexamine(name,&fileinfo))) {
  1040.         if ((cust=findfile(dopus_curwin[win],fileinfo.fib_FileName,NULL)))
  1041.             removefile(cust,dopus_curwin[win],win,FALSE);
  1042.         ret=(struct Directory *)addfile(dopus_curwin[win],
  1043.             win,fileinfo.fib_FileName,fileinfo.fib_Size,
  1044.             fileinfo.fib_DirEntryType,&(fileinfo.fib_Date),fileinfo.fib_Comment,
  1045.             fileinfo.fib_Protection,0,FALSE,NULL,NULL,fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
  1046.     }
  1047.     else {
  1048.         if ((cust=findfile(dopus_curwin[win],BaseName(name),NULL)))
  1049.             removefile(cust,dopus_curwin[win],win,FALSE);
  1050.     }
  1051.     return(ret);
  1052. }
  1053.  
  1054. openscriptfile(par,funcdata)
  1055. struct dopusfuncpar *par;
  1056. struct function_data *funcdata;
  1057. {
  1058.     char buf[512],buf2[512];
  1059.     struct FileInfoBlock __aligned fileinfo;
  1060.     BPTR lock;
  1061.     int a;
  1062.  
  1063.     if (funcdata->output_file) return(1);
  1064.  
  1065.     if (par->which&FLAG_CDSOURCE && !funcdata->source_path[0]) {
  1066.         if (!(simplerequest(globstring[STR_NO_SOURCE_SELECTED],
  1067.             globstring[STR_CONTINUE],str_cancelstring,NULL))) {
  1068.             myabort();
  1069.             return(0);
  1070.         }
  1071.     }
  1072.     else if (par->which&FLAG_CDDEST && !funcdata->dest_path[0]) {
  1073.         if (!(simplerequest(globstring[STR_NO_DESTINATION_SELECTED],
  1074.             globstring[STR_CONTINUE],str_cancelstring,NULL))) {
  1075.             myabort();
  1076.             return(0);
  1077.         }
  1078.     }
  1079.  
  1080.     makereselect(&func_reselection,funcdata->activewin);
  1081.  
  1082.     main_proc->pr_WindowPtr=(APTR)-1;
  1083.     if (CheckExist("T:",NULL)) strcpy(buf,"T:");
  1084.     else strcpy(buf,"RAM:");
  1085.  
  1086.     if (lock=Lock(buf,ACCESS_READ)) {
  1087.         Examine(lock,&fileinfo);
  1088.         if (ExNext(lock,&fileinfo)) {
  1089.             FOREVER {
  1090.                 if (LStrnCmp(fileinfo.fib_FileName,"dopustemp",9)==0)
  1091.                     lsprintf(funcdata->scriptname,"%s%s",buf,fileinfo.fib_FileName);
  1092.                 else funcdata->scriptname[0]=0;
  1093.                 a=ExNext(lock,&fileinfo);
  1094.                 if (funcdata->scriptname[0]) DeleteFile(funcdata->scriptname);
  1095.                 if (!a) break;
  1096.             }
  1097.         }
  1098.         UnLock(lock);
  1099.     }
  1100.     if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
  1101.  
  1102.     for (a=0;a<100;a++) {
  1103.         lsprintf(funcdata->scriptname,"%sdopustemp.tmp%ld",buf,a);
  1104.         if (funcdata->output_file=Open(funcdata->scriptname,MODE_NEWFILE)) break;
  1105.     }
  1106.     if (!funcdata->output_file) {
  1107.         doerror(IoErr());
  1108.         return(0);
  1109.     }
  1110.  
  1111.     lsprintf(funcdata->tempfile,"%sdopusout.tmp%ld",buf,a);
  1112.  
  1113.     rec_pathkey=NULL;
  1114.  
  1115.     lsprintf(buf,"%s -s\n",str_dopusrt_path);
  1116.     Write(funcdata->output_file,buf,strlen(buf));
  1117.  
  1118.     if (par->which&FLAG_SHELLUP) {
  1119.         if (config->shellstartup[0]) StrCombine(buf,"S:",config->shellstartup,40);
  1120.         else strcpy(buf,"S:Shell-Startup");
  1121.         if (CheckExist(buf,NULL)) {
  1122.             lsprintf(buf2,"Execute %s\n",buf);
  1123.             Write(funcdata->output_file,buf2,strlen(buf2));
  1124.         }
  1125.     }
  1126.     if (par->which&FLAG_DOPUSUP) {
  1127.         if (CheckExist("S:DOpus-Startup",NULL))
  1128.             Write(funcdata->output_file,"Execute S:DOpus-Startup\n",24);
  1129.         else if (CheckExist("S:DOpusShell-Startup",NULL))
  1130.             Write(funcdata->output_file,"Execute S:DOpusShell-Startup\n",29);
  1131.     }
  1132.     Write(funcdata->output_file,"FailAt 999999\n",14);
  1133.  
  1134.     buf[0]=0;
  1135.     if (status_flags&STATUS_FROMHOTKEY) {
  1136.         expand_path("",buf2);
  1137.         lsprintf(buf,"CD \"%s\"\n",buf2);
  1138.     }
  1139.     else {
  1140.         if (par->which&FLAG_CDSOURCE && funcdata->source_path[0])
  1141.             lsprintf(buf,"CD \"%s\"\n",funcdata->source_path);
  1142.         else if (par->which&FLAG_CDDEST) {
  1143.             if (!(check_dest_path(funcdata))) return(0);
  1144.             lsprintf(buf,"CD \"%s\"\n",funcdata->dest_path);
  1145.         }
  1146.     }
  1147.     if (buf[0]) Write(funcdata->output_file,buf,strlen(buf));
  1148.  
  1149.     lsprintf(buf,"Stack %ld\n",(par->stack<4000)?4000:par->stack);
  1150.     Write(funcdata->output_file,buf,strlen(buf));
  1151.  
  1152.     if (par->pri!=0) {
  1153.         lsprintf(buf,"ChangeTaskPri %ld\n",par->pri);
  1154.         Write(funcdata->output_file,buf,strlen(buf));
  1155.     }
  1156.  
  1157.     return(1);
  1158. }
  1159.  
  1160. closescriptfile(par,run,funcdata)
  1161. struct dopusfuncpar *par;
  1162. int run;
  1163. struct function_data *funcdata;
  1164. {
  1165.     struct MsgPort *msgport;
  1166.     struct Message *msg;
  1167.     char buf[256],buf2[512],portname[50],pubname[140];
  1168.     int wb2f,setcust=0,tnil=0,otemp=0,oldmodes,okayflag=0,bit,flags=0;
  1169.  
  1170.     if (run>0 && par && funcdata->output_file) {
  1171.         flags=par->which;
  1172.         if (flags&FLAG_OUTFILE && status_flags&STATUS_FROMHOTKEY) {
  1173.             flags&=~FLAG_OUTFILE;
  1174.             flags|=FLAG_OUTWIND;
  1175.         }
  1176.  
  1177.         okayflag=1;
  1178.         wb2f=flags&FLAG_WB2F;
  1179.         msgport=NULL;
  1180.         endnotifies();
  1181.  
  1182.         if (flags&FLAG_OUTWIND) {
  1183.             lsprintf(buf2,"%s \"%s\" from %s",config->outputcmd,config->output,funcdata->scriptname);
  1184.             if (!(flags&FLAG_ASYNC)) {
  1185.                 lsprintf(portname,"dopus_run%ld",system_dopus_runcount);
  1186.                 if (!(msgport=LCreatePort(portname,0))) goto freeargs;
  1187.             }
  1188.             else wb2f=1;
  1189.         }
  1190.         else if (flags&FLAG_ASYNC) lsprintf(buf2,"run execute %s",funcdata->scriptname);
  1191.         else lsprintf(buf2,"execute %s",funcdata->scriptname);
  1192.  
  1193.         if (flags&FLAG_OUTWIND) {
  1194.             if (par->delay!=0) {
  1195.                 lsprintf(buf,"%s -w %ld \"%s\"\n",
  1196.                     str_dopusrt_path,
  1197.                     par->delay,
  1198.                     globstring[STR_PRESS_MOUSE_BUTTON]);
  1199.                 Write(funcdata->output_file,buf,strlen(buf));
  1200.             }
  1201.             if (msgport) {
  1202.                 lsprintf(buf,"%s -p %s\n",str_dopusrt_path,portname);
  1203.                 Write(funcdata->output_file,buf,strlen(buf));
  1204.             }
  1205.             Write(funcdata->output_file,"EndCLI >NIL:\n",13);
  1206.         }
  1207.  
  1208.         Close(funcdata->output_file); funcdata->output_file=0;
  1209.  
  1210.         if (wb2f && (!(flags&FLAG_ASYNC) || !(flags&FLAG_DOPUSF)))
  1211.             WBenchToFront();    
  1212.         if (flags&FLAG_OUTWIND && !wb2f && MainScreen) {
  1213.             if (system_version2) {
  1214.                 oldmodes=SetPubScreenModes(SHANGHAI);
  1215.                 GetDefaultPubScreen(pubname);
  1216.                 SetDefaultPubScreen((UBYTE *)str_arexx_portname);
  1217.             }
  1218.             else {
  1219.                 Forbid();   
  1220.                 MainScreen->Flags&=~CUSTOMSCREEN;
  1221.                 MainScreen->Flags|=WBENCHSCREEN;
  1222.                 Permit();
  1223.             }
  1224.             setcust=1;
  1225.         }
  1226.  
  1227.         if (flags&FLAG_OUTFILE && (tnil=Open(funcdata->tempfile,MODE_NEWFILE))) otemp=1;
  1228.         if (!tnil) tnil=Open("NIL:",MODE_OLDFILE);
  1229.  
  1230.         Execute(buf2,0,(BPTR)tnil);
  1231.  
  1232.         if (flags&FLAG_OUTWIND && !wb2f && !(status_flags&STATUS_IANSCRAP) && MainScreen) {
  1233.             if (system_version2) {
  1234.                 SetDefaultPubScreen(pubname);
  1235.                 SetPubScreenModes(oldmodes);
  1236.             }
  1237.             else {
  1238.                 Forbid();   
  1239.                 MainScreen->Flags&=~WBENCHSCREEN;
  1240.                 MainScreen->Flags|=CUSTOMSCREEN;
  1241.                 Permit();
  1242.             }
  1243.             setcust=0;
  1244.         }
  1245.  
  1246.         if (msgport && Window) {
  1247.             SetSignal(0,INPUTSIG_ABORT);
  1248.             FOREVER {
  1249.                 if ((bit=Wait(1<<msgport->mp_SigBit|rexx_signalbit|INPUTSIG_ABORT))
  1250.                     &INPUTSIG_ABORT) {
  1251.                     status_justabort=status_haveaborted=0;
  1252.                     break;
  1253.                 }
  1254.                 if (bit&rexx_signalbit) {
  1255.                     rexx_dispatch(0);
  1256.                     continue;
  1257.                 }
  1258.                 if ((msg=GetMsg(msgport))) {
  1259.                     ReplyMsg(msg);
  1260.                     break;
  1261.                 }
  1262.             }
  1263.             LDeletePort(msgport);
  1264.         }
  1265.  
  1266.         if (!(flags&FLAG_ASYNC) && tnil) Close(tnil);
  1267.  
  1268.         if (setcust) {
  1269.             if (system_version2) {
  1270.                 SetDefaultPubScreen(pubname);
  1271.                 SetPubScreenModes(oldmodes);
  1272.             }
  1273.             else {
  1274.                 Forbid();   
  1275.                 MainScreen->Flags&=~WBENCHSCREEN;
  1276.                 MainScreen->Flags|=CUSTOMSCREEN;
  1277.                 Permit();
  1278.             }
  1279.         }
  1280.  
  1281.         if (flags&FLAG_DOPUSF) {
  1282.             if (MainScreen) ScreenToFront(MainScreen);
  1283.             if (Window && !Window->Flags&WFLG_BACKDROP) WindowToFront(Window);
  1284.         }
  1285.  
  1286.         if (!status_iconified && !(status_flags&STATUS_FROMHOTKEY)) {
  1287.             if (funcdata->rereadsource || flags&FLAG_SCANSRCE) {
  1288.                 startgetdir(funcdata->activewin,0);
  1289.                 funcdata->reload_first=NULL;
  1290.             }
  1291.             if (funcdata->rereaddest || flags&FLAG_SCANDEST)
  1292.                 startgetdir(funcdata->inactivewin,0);
  1293.             if (flags&FLAG_RELOAD && funcdata->reload_first) doreloadfiles(funcdata);
  1294.         }
  1295.     }
  1296.  
  1297. freeargs:
  1298.     if (funcdata->output_file) Close(funcdata->output_file);
  1299.     if ((funcdata->output_file || okayflag) && funcdata->scriptname[0] &&
  1300.         (!par || !(flags&FLAG_ASYNC)))
  1301.         DeleteFile(funcdata->scriptname);
  1302.     funcdata->output_file=funcdata->scriptname[0]=0;
  1303.     funcdata->rereaddest=funcdata->rereadsource=0;
  1304.  
  1305.     LFreeRemember(&funcdata->arg_memkey);
  1306.     if (otemp) {
  1307.         viewfile(funcdata->tempfile,globstring[STR_TEMPORARY_OUTPUT_FILE],FUNC_READ,NULL,NULL,1,0);
  1308.         DeleteFile(funcdata->tempfile);
  1309.     }
  1310.     LFreeRemember(&rec_pathkey);
  1311.     LFreeRemember(&funcdata->reload_memkey);
  1312.  
  1313.     if (Window && !(status_flags&STATUS_FROMHOTKEY)) unbusy();
  1314.     if (status_flags&STATUS_VERIFYFAIL) myabort();
  1315.     else if (okayflag) {
  1316.         if (Window && !status_iconified && !(status_flags&STATUS_FROMHOTKEY)) okay();
  1317.         if (flags&FLAG_ICONIFY && checkwindowquit()) iconify(2,0,0);
  1318.         else startnotifies();
  1319.     }
  1320.     return(run);
  1321. }
  1322.  
  1323. getdummyfile(fbuf,dirbuf,freq)
  1324. struct Directory *fbuf;
  1325. char *dirbuf;
  1326. struct DOpusFileReq *freq;
  1327. {
  1328.     char file[32],buf[300];
  1329.  
  1330.     freq->x=freq->y=-2;
  1331.     freq->title=globstring[STR_SELECT_A_FILE]; file[0]=0;
  1332.     freq->dirbuf=dirbuf; freq->filebuf=file;
  1333.     freq->window=Window;
  1334.     freq->lines=15; freq->flags=0;
  1335.     if (!dirbuf[0]) expand_path("",dirbuf);
  1336.     if (!(FileRequest(freq))) {
  1337.         myabort();
  1338.         return(0);
  1339.     }
  1340.     if (!dirbuf[0]) expand_path("",dirbuf);
  1341.     if (fbuf) {
  1342.         strcpy(buf,dirbuf); TackOn(buf,file,256);
  1343.         return(filloutdummy(buf,fbuf));
  1344.     }
  1345.     strcpy(func_single_file,file);
  1346.     return(1);
  1347. }
  1348.  
  1349. filloutdummy(name,fbuf)
  1350. char *name;
  1351. struct Directory *fbuf;
  1352. {
  1353.     struct FileInfoBlock __aligned fib;
  1354.  
  1355.     if (!(lockandexamine(name,&fib))) return(0);
  1356.     fbuf->last=fbuf->next=NULL;
  1357.     strcpy(fbuf->name,fib.fib_FileName);
  1358.     fbuf->type=fib.fib_DirEntryType;
  1359.     if (fbuf->type>=0) fbuf->size=-1;
  1360.     else fbuf->size=fib.fib_Size;
  1361.     fbuf->subtype=0;
  1362.     fbuf->protection=fib.fib_Protection;
  1363.     fbuf->comment=fbuf->dispstr=NULL;
  1364.     getprot(fbuf->protection,fbuf->protbuf);
  1365.     seedate(&fib.fib_Date,fbuf->datebuf,1);
  1366.     CopyMem((char *)&fib.fib_Date,&fbuf->date,sizeof(struct DateStamp));
  1367.     fbuf->selected=1;
  1368.     return(1);
  1369. }
  1370.  
  1371. dirrequester(freq,buf,title)
  1372. struct DOpusFileReq *freq;
  1373. char *buf,*title;
  1374. {
  1375.     if (title) freq->title=title;
  1376.     else freq->title=globstring[STR_SELECT_A_DIRECTORY];
  1377.     freq->dirbuf=buf;
  1378.     freq->flags=DFRF_DIRREQ;
  1379.     if (!buf[0]) expand_path("",buf);
  1380.     if (FileRequest(freq)) {
  1381.         if (!buf[0]) expand_path("",buf);
  1382.         return(1);
  1383.     }
  1384.     return(0);
  1385. }
  1386.  
  1387. void do_title_string(string,buf,ml,name)
  1388. char *string,*buf;
  1389. int ml;
  1390. char *name;
  1391. {
  1392.     int a,b,c;
  1393.  
  1394.     a=strlen(string); c=0;
  1395.     for (b=0;b<a;b++) {
  1396.         if (string[b]=='%') {
  1397.             buf[c]=0;
  1398.             if (name) strcat(buf,name);
  1399.             else addreqfilename(buf,data_active_window);
  1400.             c=strlen(buf);
  1401.         }
  1402.         else {
  1403.             if (ml && string[b]=='\\') buf[c]='\n';
  1404.             else buf[c]=string[b];
  1405.             ++c;
  1406.         }
  1407.         if (c==(256+(ml*262))) break;
  1408.     }
  1409.     buf[c]=0;
  1410. }
  1411.  
  1412. void addreqfilename(buf,win)
  1413. char *buf;
  1414. int win;
  1415. {
  1416.     struct Directory *dir;
  1417.  
  1418.     if (func_single_file[0]) strcat(buf,func_single_file);
  1419.     else {
  1420.         dir=dopus_curwin[win]->firstentry;
  1421.         while (dir) {
  1422.             if (dir->selected && dir->type<0) break;
  1423.             dir=dir->next;
  1424.         }
  1425.         if (dir && dir->selected && dir->type<0) strcat(buf,dir->name);
  1426.     }
  1427. }
  1428.  
  1429. struct Directory *custgetfirst(funcdata)
  1430. struct function_data *funcdata;
  1431. {
  1432.     struct Directory *file;
  1433.  
  1434.     file=funcdata->entry_first;
  1435.     while (file) {
  1436.         if (file->type!=0 && file->selected && file->type!=ENTRY_CUSTOM) return(file);
  1437.         file=file->next;
  1438.     }
  1439.     return(NULL);
  1440. }
  1441.  
  1442. void custnextsel(dir)
  1443. struct Directory **dir;
  1444. {
  1445.     while (*dir) {
  1446.         if (!(*dir=(*dir)->next)) break;
  1447.         if ((*dir)->selected) break;
  1448.     }
  1449. }
  1450.  
  1451. check_dest_path(funcdata)
  1452. struct function_data *funcdata;
  1453. {
  1454.     if (funcdata->dest_path[0]) return(1);
  1455.     if ((status_iconified || status_flags&STATUS_FROMHOTKEY) &&
  1456.         ((dirrequester(&funcdata->file_request,
  1457.         funcdata->dest_path,globstring[STR_SELECT_DESTINATION_DIR])) ||
  1458.         !funcdata->dest_path[0])) {
  1459.         myabort();
  1460.         return(0);
  1461.     }
  1462.     if (!funcdata->dest_path[0]) {
  1463.         dostatustext(globstring[STR_NO_DESTINATION_SELECTED]);
  1464.         simplerequest(globstring[STR_NO_DESTINATION_SELECTED],
  1465.             globstring[STR_CONTINUE],NULL);
  1466.         return(0);
  1467.     }
  1468.     return(1);
  1469. }
  1470.  
  1471. getdummypath(dir,title)
  1472. char *dir;
  1473. int title;
  1474. {
  1475.     struct DOpusFileReq freq;
  1476.     int a;
  1477.  
  1478.     freq.window=Window;
  1479.     freq.lines=15;
  1480.     freq.x=freq.y=-2;
  1481.     if ((a=dirrequester(&freq,dir,globstring[title])))
  1482.         if (!dir[0]) expand_path("",dir);
  1483.     return(a);
  1484. }
  1485.  
  1486. void build_default_string(string,buffer,filename,sourcepath,destpath)
  1487. char *string,*buffer,*filename,*sourcepath,*destpath;
  1488. {
  1489.     int len,a,pos,flag;
  1490.     char *ptr;
  1491.  
  1492.     len=strlen(string);
  1493.     pos=0;
  1494.     for (a=0;a<len && pos<499;a++) {
  1495.         if (string[a]=='[' && string[a+2]==']') {
  1496.             flag=1;
  1497.             switch (string[a+1]) {
  1498.                 case 'f':
  1499.                     LStrnCpy(&buffer[pos],filename,499-pos);
  1500.                     break;
  1501.                 case 'o':
  1502.                     if (ptr=BaseName(filename)) LStrnCpy(&buffer[pos],ptr,499-pos);
  1503.                     break;
  1504.                 case 's':
  1505.                     LStrnCpy(&buffer[pos],sourcepath,499-pos);
  1506.                     break;
  1507.                 case 'd':
  1508.                     LStrnCpy(&buffer[pos],destpath,499-pos);
  1509.                     break;
  1510.                 default:
  1511.                     flag=0;
  1512.                     break;
  1513.             }
  1514.             if (flag) {
  1515.                 pos=strlen(buffer);
  1516.                 a+=2;
  1517.                 continue;
  1518.             }
  1519.         }
  1520.         buffer[pos++]=string[a];
  1521.     }
  1522. }
  1523.